package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class jdbc_study2 {
    public static void main(String[] args) {
        Statement stmt = null;
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String sql = "create table teacher(id int,name varchar(20))";
            conn = DriverManager.getConnection("jdbc:mysql:///db", "root", "root");
            stmt = conn.createStatement();
            int count = stmt.executeUpdate(sql);
            if (count >= 0) {
                System.out.println(count);
                System.out.println("成功");
            } else {
                System.out.println("失败");
            }
            count = stmt.executeUpdate("insert into teacher values (1,'李狗蛋'),(2,'王狗蛋')");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println(e);
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
